Skip to content

fix(archiver): throw on duplicate contract class or instance additions#21799

Merged
PhilWindle merged 2 commits intomerge-train/spartanfrom
palla/throw-on-duplicate-contract-data
Mar 20, 2026
Merged

fix(archiver): throw on duplicate contract class or instance additions#21799
PhilWindle merged 2 commits intomerge-train/spartanfrom
palla/throw-on-duplicate-contract-data

Conversation

@spalladino
Copy link
Contributor

Motivation

The contract instance store used .set() which silently overwrote existing entries, while the contract class store used .setIfNotExists() which silently ignored duplicates. Neither behavior catches the unexpected case of a double-add, which could lead to data loss on rollback — if an instance is added at block N and again at block M, rolling back block M would delete the instance entirely, invalidating the first add. The protocol prevents this via deployer nullifiers, but the store should enforce it as defense-in-depth.

Approach

Both addContractInstance and addContractClass now check for existing entries and throw if the key already exists. This surfaces any unexpected double-adds as errors rather than silently corrupting state.

Changes

  • archiver (contract_instance_store): addContractInstance checks hasAsync before writing; throws with a descriptive error on duplicate
  • archiver (contract_class_store): addContractClass replaces setIfNotExists with explicit hasAsync check and throw on duplicate
  • archiver (tests): Updated "add twice" tests to expect throws instead of silent success

spalladino and others added 2 commits March 19, 2026 14:43
Replace silent overwrites with explicit errors when adding a contract
class or instance that already exists in the store. This catches
unexpected double-adds that could lead to data loss on rollback.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Makes registerProtocolContracts idempotent by checking if the contract
class already exists before adding. This handles node restarts against
a persisted LMDB store.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@PhilWindle PhilWindle merged commit 6d5f055 into merge-train/spartan Mar 20, 2026
19 of 23 checks passed
@PhilWindle PhilWindle deleted the palla/throw-on-duplicate-contract-data branch March 20, 2026 09:24
AztecBot pushed a commit that referenced this pull request Mar 20, 2026
#21799)

## Motivation

The contract instance store used `.set()` which silently overwrote
existing entries, while the contract class store used
`.setIfNotExists()` which silently ignored duplicates. Neither behavior
catches the unexpected case of a double-add, which could lead to data
loss on rollback — if an instance is added at block N and again at block
M, rolling back block M would delete the instance entirely, invalidating
the first add. The protocol prevents this via deployer nullifiers, but
the store should enforce it as defense-in-depth.

## Approach

Both `addContractInstance` and `addContractClass` now check for existing
entries and throw if the key already exists. This surfaces any
unexpected double-adds as errors rather than silently corrupting state.

## Changes

- **archiver (contract_instance_store)**: `addContractInstance` checks
`hasAsync` before writing; throws with a descriptive error on duplicate
- **archiver (contract_class_store)**: `addContractClass` replaces
`setIfNotExists` with explicit `hasAsync` check and throw on duplicate
- **archiver (tests)**: Updated "add twice" tests to expect throws
instead of silent success
@AztecBot
Copy link
Collaborator

✅ Successfully backported to backport-to-v4-next-staging #21819.

github-merge-queue bot pushed a commit that referenced this pull request Mar 20, 2026
BEGIN_COMMIT_OVERRIDE
feat(p2p): add tx validator for contract instance deployment addresses
(#21771)
fix: always deploy IRM for testnet (#21755)
fix: avoid mutating caller's array via splice in snapshot sync (A-718)
(#21759)
chore: update network logs skill (#21785)
feat(archiver): validate contract instance addresses before storing
(#21787)
fix: ensure no division by 0 (#21786)
feat: support private fork releases via ci-release (#21778)
fix: restrict scenario deployments to only nightly (#21798)
fix(stdlib): zero-pad bufferFromFields when declared length exceeds
payload (#21802)
test(protocol-contracts): verify max-size bytecode fits in contract
class log (#21818)
fix: wire BOT_DA_GAS_LIMIT through helm/terraform for staging-public
(#21809)
fix: remove jest-mock-extended from worker processes + fix
parallelize_strict silent failures (#21821)
fix(archiver): throw on duplicate contract class or instance additions
(#21799)
chore: remove broadcasted function events (#21805)
fix: sync dateProvider from anvil stdout on every mined block (#21829)
fix(sequencer): use wall-clock time instead of L1 block timestamp for
slot estimation (#21769)
fix: use correct EthCheatCodes method name in epochs_missed_l1_slot test
(#21848)
feat(p2p): add tx validator for contract class id verification (#21788)
feat: publisher funding (#21631)
feat: batch chonk verifier TS integration (#21823)
fix(sequencer): remove l1 block timestamp check (#21853)
fix: use local IVC inputs for batch_verifier bench test (#21857)
fix(p2p): centralize gossipsub penalization and fix inconsistencies
(#21863)
chore: publish GitHub releases to AztecProtocol/barretenberg (#21775)
END_COMMIT_OVERRIDE
AztecBot added a commit that referenced this pull request Mar 21, 2026
BEGIN_COMMIT_OVERRIDE
chore: backport #21754 (feat!: make isContractInitialized a tri-state
enum) to v4-next (#21792)
fix(stdlib): zero-pad bufferFromFields when declared length exceeds
payload (#21802)
test(protocol-contracts): verify max-size bytecode fits in contract
class log (#21818)
chore: port P2P mesh topic deflake fix to v4-next (#21825)
fix(archiver): throw on duplicate contract class or instance additions
(#21799)
feat: sync poseidon in the browser (#21833)
chore: backport #21824 (fix(aztec-up): add sensible defaults to
installer y/n prompts) to v4-next (#21844)
fix(sequencer): backport wall-clock time for slot estimation to v4-next
(#21769) (#21847)
chore: backport PR #21788 (feat(p2p): add tx validation for contract
class id verification) to v4-next (#21852)
feat: sync poseidon browser (#21851)
END_COMMIT_OVERRIDE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants